<?php
define("APP_DIR", realpath(dirname(dirname(__FILE__)))."/");
include APP_DIR."Libs/Class/AutoloadClass.class.php";
$AutoLoadClass = AutoloadClass::single();
$AutoLoadClass->regDir(APP_DIR."Model/");
$AutoLoadClass->run();
$SystemConfig = Config::single()->loadConfig("test");
$_GROUPS = $SystemConfig->getGroups();
$_ENV['_G'] = $SystemConfig->getDefaultGroup();
//$_ENV['_C'] = $_GROUPS["Groups"][$_ENV['_G']]['DefaultController'];
//$_ENV['_M'] = $_GROUPS["Groups"][$_ENV['_G']]['DefaultMethod'];
$url = $_SERVER["REQUEST_URI"];
$url = explode("/", $url);
if(isset($url[1])){
	$t1 = ucfirst(strtolower($url[1]));
	if(in_array($t1, $_GROUPS)){
		$_ENV['_G'] = $t1;
		if(isset($url[2])){
			$t1 = ucfirst(strtolower($url[2]));
			$_ENV['_C'] = $t1;
			if(isset($url[3])){
				$t1 = strtolower($url[3]);
				$_ENV['_M'] = $t1;
			}
		}
	}else{
		$_ENV['_C'] = $t1;
		if(isset($url[2])){
			$t1 = strtolower($url[2]);
			$_ENV['_M'] = $t1;
		}
	}
	
}
$appfile = APP_DIR."Libs/App/".$_ENV['_G'].".app.php";
if(file_exists($appfile)){
	include $appfile;
	$cls = $_ENV['_G']."App";
	$app = new $cls;
}
$path = APP_DIR.'Controller/'.$_ENV['_G']."/".$_ENV['_C'].'.controller.php';
if(file_exists($path)){
	include $path;
	$cls = $_ENV['_C']."Controller";
	$Controller = new $cls;
	$Controller->$_ENV['_M']();
}else{
	echo "canshu cuowu ";
}


//var_dump($_ENV);
